package com.edu.exam.entity.quality.monitoring;

import com.edu.exam.enums.PatrolTaskApprovalStatus;
import com.edu.exam.enums.PatrolTaskDifficultyLevel;
import com.edu.exam.enums.PatrolTaskPriorityLevel;
import com.edu.exam.enums.PatrolTaskRiskLevel;
import com.edu.exam.enums.PatrolTaskSafetyLevel;
import com.edu.exam.enums.quality.monitoring.MonitoringTaskStatus;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

/**
 * 巡考任务实体类
 *
 * 负责管理巡考任务的基本信息和状态
 * 根据E-05-巡考管理模块设计实现
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class PatrolTask {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "task_name", nullable = false, length = 200)
    private String taskName;

    @Column(name = "exam_id", nullable = false)
    private Long examId;

    @Column(name = "exam_name", nullable = false, length = 200)
    private String examName;

    @Column(name = "exam_room_id", nullable = false)
    private Long examRoomId;

    @Column(name = "exam_room_name", nullable = false, length = 200)
    private String examRoomName;

    @Column(name = "start_time", nullable = false)
    private LocalDateTime startTime;

    @Column(name = "end_time", nullable = false)
    private LocalDateTime endTime;

    @Column(name = "assigned_user_id")
    private Long assignedUserId;

    @Column(name = "assigned_user_name", length = 100)
    private String assignedUserName;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private MonitoringTaskStatus status;

    @Column(name = "requirements", columnDefinition = "TEXT")
    private String requirements;

    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    @Column(name = "created_by", length = 100)
    private String createdBy;

    @Column(name = "priority_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolTaskPriorityLevel priorityLevel = PatrolTaskPriorityLevel.NORMAL;

    @Column(name = "estimated_duration")
    private Integer estimatedDuration; // 预估巡考时长（分钟）

    @Column(name = "special_instructions", columnDefinition = "TEXT")
    private String specialInstructions; // 特殊说明

    @Column(name = "contact_phone", length = 20)
    private String contactPhone; // 联系电话

    @Column(name = "emergency_contact", length = 100)
    private String emergencyContact; // 紧急联系人

    @Column(name = "location_description", length = 500)
    private String locationDescription; // 位置描述

    @Column(name = "access_requirements", length = 500)
    private String accessRequirements; // 进入要求

    @Column(name = "equipment_needed", length = 500)
    private String equipmentNeeded; // 所需设备

    @Column(name = "weather_conditions", length = 200)
    private String weatherConditions; // 天气情况

    @Column(name = "traffic_conditions", length = 200)
    private String trafficConditions; // 交通情况

    @Column(name = "safety_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolTaskSafetyLevel safetyLevel = PatrolTaskSafetyLevel.NORMAL;

    @Column(name = "completion_notes", columnDefinition = "TEXT")
    private String completionNotes; // 完成备注

    @Column(name = "actual_start_time")
    private LocalDateTime actualStartTime; // 实际开始时间

    @Column(name = "actual_end_time")
    private LocalDateTime actualEndTime; // 实际结束时间

    @Column(name = "actual_duration")
    private Integer actualDuration; // 实际用时（分钟）

    @Column(name = "completion_percentage")
    private Double completionPercentage = 0.0; // 完成百分比

    @Column(name = "difficulty_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolTaskDifficultyLevel difficultyLevel = PatrolTaskDifficultyLevel.NORMAL;

    @Column(name = "risk_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolTaskRiskLevel riskLevel = PatrolTaskRiskLevel.LOW;

    @Column(name = "collaboration_required")
    private Boolean collaborationRequired = false; // 是否需要协作

    @Column(name = "supervisor_id")
    private Long supervisorId; // 监督人ID

    @Column(name = "supervisor_name", length = 100)
    private String supervisorName; // 监督人姓名

    @Column(name = "approval_status", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolTaskApprovalStatus approvalStatus = PatrolTaskApprovalStatus.PENDING;

    @Column(name = "approved_by", length = 100)
    private String approvedBy; // 审批人

    @Column(name = "approval_time")
    private LocalDateTime approvalTime; // 审批时间

    @Column(name = "approval_comments", columnDefinition = "TEXT")
    private String approvalComments; // 审批意见

    @Column(name = "auto_assignment_enabled")
    private Boolean autoAssignmentEnabled = false; // 是否启用自动分配

    @Column(name = "assignment_preferences", columnDefinition = "TEXT")
    private String assignmentPreferences; // 分配偏好（JSON格式）

    @Column(name = "notification_settings", columnDefinition = "TEXT")
    private String notificationSettings; // 通知设置（JSON格式）

    @Column(name = "report_template", length = 200)
    private String reportTemplate; // 报告模板

    @Column(name = "quality_standards", columnDefinition = "TEXT")
    private String qualityStandards; // 质量标准

    @Column(name = "evaluation_criteria", columnDefinition = "TEXT")
    private String evaluationCriteria; // 评估标准

    @Column(name = "version_number")
    private Integer versionNumber = 1; // 版本号

    @Column(name = "archived")
    private Boolean archived = false; // 是否归档

    @Column(name = "archive_time")
    private LocalDateTime archiveTime; // 归档时间

    @Column(name = "archive_reason", length = 500)
    private String archiveReason; // 归档原因

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata; // 元数据（JSON格式）

}
